﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            Register register = new Register();
            register.Show();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            var name = this.textBox1.Text;
            var pwd = this.textBox2.Text;
            var cmdString = "server=.;database=Register;uid=sa;pwd=123456";
            SqlConnection connection = new SqlConnection(cmdString);
            connection.Open();
            var select = "select*from Load ";
            SqlCommand command = new SqlCommand(select,connection);
            command.Connection = connection;
            command.CommandText = "select*from Load where Name=@name";
            command.Parameters.AddWithValue("@name",this.textBox1.Text);
            SqlDataReader reader = command.ExecuteReader();
            if (reader.Read())
            {
                this.textBox1.Text = reader["Name"].ToString();
                this.textBox2.Text = reader["Password"].ToString();
                if (name == this.textBox1.Text && pwd == this.textBox2.Text)
                {
                    MessageBox.Show("登录成功");
                    WinForm winForm = new WinForm();
                    this.Hide();
                    winForm.Show();

                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
            else 
            {
                MessageBox.Show("请填入正确的用户名或密码");
            }

           


        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
